<?php
	global $user;
	$username = $user->name;

    global $global_ws_address;
	
	$productList = array();
	$cveList = array();
	$i=0;
	$j=0;
	
	while($_POST['product'.$i]){
		$productList[] = $_POST['product'.$i];
		$i++;
	}

	while($_POST['cve'.$j]){
		$cveList[] = $_POST['cve'.$j];
		$j++;
	}

	$email = $_POST['email'];
	if($email) $notification_email = 1;
	else  $notification_email = 0;
	
	$tel = $_POST['sms'];
	if($tel) $notification_sms = 1;
	else  $notification_sms = 0;
	
	$twitter = $_POST['twitter'];
	if($twitter) $notification_twitter = 1;
	else  $notification_twitter = 0;

	$result = array();
	$result['username'] = $username;
	$result['notification_email'] = $notification_email;
	$result['notification_sms'] = $notification_sms;
	$result['notification_twitter'] = $notification_twitter;
	$result['email'] = $email;
	$result['tel'] = $tel;
	$result['twitter'] = $twitter;
	$result['product'] = $productList;
	$result['cve'] = $cveList;

	$result = json_encode($result);

	$context = stream_context_create(array(
		'http' => array(
				'timeout' => 10      // Timeout in seconds
		)
	));

	$url = $global_ws_address.'o=setuserinfo&p1='.$result;
	$success = @file_get_contents($url,0,$context);

	if($success) header('Location:?q=node/3');
	else echo 'The operation has failed. Please try again.';
?>